from Cube.utility.SerialNumberGen import SerialNumberGen
# send directly
from Cube.command.QCmdInputPipe.QCmdQueue import CmdQueueInit, CmdQueuePush
from Cube.command.QCmdInputPipe.EventDefine import event_QNETWORK_SENDDIRECTLY

# remember to import CmdIDGen in child class of QCommand to get CMDID
CmdIDGen = SerialNumberGen().Gen

class QCommand:
    CmdQueue = None
    CMDID = CmdIDGen()
    CMDNAME = "QCommand"
    MyMemberID = 0

    # send to SendOutCmdQueue
    def InputSend(self, memberID, param):
        #print "%s.InputSend: memerID=%d, param=%s"%(self.CMDNAME,memberID,param)
        self.CmdQueue.InputCmdQueuePush(memberID, self.CMDID, param)

    # send to ExeCmdQueue
    def ExeSend(self, memberID, param):
        #print "%s.ExecSend: memerID=%d, param=%s"%(self.CMDNAME,memberID,param)
        self.CmdQueue.ExeCmdQueuePush(memberID, self.CMDID, param)

    # special mode for client join process
    def SendDirectly(self, memberID, param, LinkID=None):
        cmdQueue = CmdQueueInit()
        CmdQueuePush(cmdQueue, memberID, self.CMDID, param)
        messenger.send(event_QNETWORK_SENDDIRECTLY, [cmdQueue, LinkID])

    # call back of parsing - override it
    def Handle(self, memberID, param):
        #print "%s.Handle: memberID=%d, param=%s"%(self.CMDNAME, memberID, param)
        pass
